package cn.desk.parameter.entity;

import javax.persistence.Entity;
import javax.persistence.Id;

import cn.desk.commons.entity.BaseEntity;

@Entity(name="t_parameter")
public class Parameter extends BaseEntity {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	private String id;
	private String parameterValue;
	private Integer putSession;
	private Integer parameterType;
	private String description;
	@Override
	public Object getValue() {
		return getParameterValue();
	}

	@Override
	public String getDisplayName() {
		return "系统";
	}

	public String getParameterValue() {
		return parameterValue;
	}
	
	public void setParameterValue(String parameterValue) {
		this.parameterValue = parameterValue;
	}

	public Integer getParameterType() {
		return parameterType;
	}

	public void setParameterType(Integer parameterType) {
		this.parameterType = parameterType;
	}

	public Integer isPutSession() {
		return putSession;
	}
	public Integer getPutSession() {
		return putSession;
	}

	public void setPutSession(Integer putSession) {
		this.putSession = putSession;
	}
	
	public String getDisplayParameterType(){
		if(parameterType==null){
			return "";
		}
		switch (parameterType) {
		case 0:
			return  "字符串";
		case 1:
			return  "整数";
		case 2:
			return  "小数";
		default:
			break;
		}
		return "字符串";
	}
	
	public Object getRealValue(){
		if(parameterType==null){
			return "";
		}
		if(parameterValue==null){
			return "";
		}
		switch (parameterType) {
		case 0:
			return  parameterValue;
		case 1:
			try {
				return Integer.parseInt(parameterValue);
			} catch (NumberFormatException e) {
				return null;
			}
		case 2:
			try {
				return  Double.parseDouble(parameterValue);
			} catch (NumberFormatException e) {
				return null;
			}
		}
		throw new RuntimeException("参数和类型不匹配");
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
